
## Snakes on a Payload
## Copyright (C) 2011 CORE Security Technologies
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License
## as published by the Free Software Foundation; either version 2
## of the License, or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
##
## Authors:
## 2011/09/11 - Pedro Varangot (pvarangot@)
## 2011/09/11 - Fernando Russ (fruss@)






class Symbol(object):
    def __init__(self, num = 0, value = 0, size = 0, _type = 0, binding = 0, visibility = 0, ndx = 0, name = ""):
        self.num = num
        self.value = value
        self.size = size
        self._type = _type
        self.binding = binding
        self.visibility = visibility
        self.ndx = ndx        
        self.name, self.version = self._demangle(name)
    
    @property
    def defined(self): return self.ndx != "UND"
    
    def _demangle(self, sym):
        #
        # demangle @version from the name
        #
        items = sym.split("@@")
        items.append(None)
        return items[0], items[1] # name, version


class UnresolvedSymbol(Symbol):
    def __init__(self, name):
        self.name = name
        Symbol.__init__(self, name = name )
